
#include <Element.h>

Element::Element() : element(0)
{
}

Element::Element(char* elem) : element(0)
{
	element = new char[strlen(elem)+1];
	strcpy(element, elem);
}

Element::Element(const Element& from)
{
	element = new char[from.length()+1];
	strcpy(element, from.element);
}

Element& Element::operator=(const Element& from)
{
	if ( this == &from )
		return *this;
	delete[] element;
	element = new char[from.length()+1];
	strcpy(element, from.element);
	return *this;
}

int Element::length() const
{
	if ( element )
		return strlen(element);
	return 0;
}

char* Element::get() const
{
	return element;
}

Element::~Element()
{
	delete[] element;
}

int operator==(const Element& one, const Element& two)
{
	if ( !strcmp(one.element, two.element) ) return 1;
	return 0;
}

int operator<(const Element& one, const Element& two)
{
	return (strcmp(one.element, two.element) < 0);
}

int operator<=(const Element& one, const Element& two)
{
	if ( (one == two) || (one < two) )
		return 1;
	return 0;
}

ostream& operator<<(ostream& os, const Element& elem)
{
	if ( elem.element )
		return os << elem.get();
	else
		return os;
}

